package com.wms.oms.controller;

import com.wms.common.core.web.controller.BaseController;
import com.wms.common.core.web.domain.AjaxResult;
import com.wms.common.core.web.page.TableDataInfo;
import com.wms.common.security.annotation.PreAuthorize;
import com.wms.oms.domain.Payment;
import com.wms.oms.service.IPaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zzm
 * @date 2023/8/25
 * @desc
 */
public class PaymentController extends BaseController {

    @Autowired
    private IPaymentService paymentService;


    /**
     * 查询付款单列表
     */
    @PreAuthorize(hasPermi = "oms:payment:list")
    @GetMapping("/list")
    public TableDataInfo list(Payment payment)
    {
        startPage();
        List<Payment> list = paymentService.selectPaymentList(payment);
        return getDataTable(list);
    }


    /**
     * 获取付款单详细信息
     */
    @PreAuthorize(hasPermi = "oms:payment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Payment payment =  paymentService.selectPaymentById(id);
        return AjaxResult.success(payment);
    }


    /**
     * 新增付款单
     */
    @PreAuthorize(hasPermi = "oms:payment:add")
    @PostMapping(value = "save")
    public AjaxResult add(@RequestBody @Valid Payment payment)
    {
        return toAjax(paymentService.insertPayment(payment));
    }


    /**
     * 修改付款单
     */
    @PreAuthorize(hasPermi = "oms:payment:edit")
    @PostMapping(value = "update")
    public AjaxResult edit(@RequestBody @Valid Payment payment)
    {
        return toAjax(paymentService.updatePayment(payment));
    }


    /**
     * 付款确认
     */
    @PreAuthorize(hasPermi = "oms:payment:edit")
    @PostMapping(value = "confirm/{id}")
    public AjaxResult confirm(@PathVariable("id") Long id)
    {
        Payment payment = paymentService.selectPaymentById(id);
        return toAjax(paymentService.confirm(payment));
    }


    /**
     * 删除付款单
     */
    @PreAuthorize(hasPermi = "oms:payment:remove")
    @PostMapping(value = "delete/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(paymentService.deletePaymentByIds(ids));
    }
}
